﻿using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;



/// <summary>
/// 字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。
/// 请定义一个函数实现字符串左旋转操作的功能。比如，输入字符串"abcdefg"和数字2，
/// 该函数将返回左旋转两位得到的结果"cdefgab"。
/// https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/
/// </summary>

public class Code058
{
    public string ReverseLeftWords(string s, int n)
    {
        return (s + s).Substring(n, s.Length);
    }
}

/// <summary>
/// 1512. 好数对的数目
/// https://leetcode-cn.com/problems/number-of-good-pairs/
/// </summary>
public class code1512
{
    public int NumIdenticalPairs(params int[] nums)
    {
        return UseMap(nums);
    }
    private int UseMap(int[] nums)
    {
        Dictionary<int, int> goodNums = new Dictionary<int, int>();
        int result = 0;
        for(int i = 0;i<nums.Length;i++)
        {
            if (goodNums.ContainsKey(nums[i]))
            {
                result += goodNums[nums[i]];
            }
            else
            {
                goodNums.Add(nums[i], 0);
            }
            goodNums[nums[i]] += 1;
        }
        return result;
    }

    private int useArray(int[] nums)
    {
        int ans = 0;
        int[] temp = new int[100];
        for (int i = 0; i < nums.Length; i++)
        {
            ans += temp[nums[i] - 1]++;
        }
        return ans;
    }
}
public class code1470
{
    public int[] startTest(int n, params int[]value)
    {
        return Shuffle(value, n);
    }
    public int[] Shuffle(int[] nums, int n)
    {
        int[] temp = new int[2 * n];
        //[2,5,1,3,4,7]
        //[2,3,4,5,1,7]
        for (int i = 0; i < n; i++)
        {
            temp[i * 2] = nums[i];
            temp[i * 2 + 1] = nums[n + i];
        }
        return temp;
    }
    /// <summary>
    /// 无敌的位运算
    /// </summary>
    /// <param name="nums"></param>
    /// <param name="n"></param>
    /// <returns></returns>
    public int [] bit(int []nums,int n)
    {
        int i = 0;
        for (i = 0; i < nums.Length; i++)
        {
            nums[i < n ? 2 * i : 2 * (i - n) + 1] |= (nums[i] & 1023) << 10;
        }
        for (i = 0; i < nums.Length; i++)
        {
            nums[i] >>= 10;
        }
        return nums;
    }
}

public class code70
{
    public int ClimbStairs(int n)
    {
        return 0;
    }
}
